package com.monkeys.service.impl;

import com.monkeys.Utils.CalculateUtil;
import com.monkeys.mapper.PoiMapper;
import com.monkeys.pojo.GoodsDemand;
import com.monkeys.pojo.Poi;
import com.monkeys.service.PoiService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
 * @author KuangTeam
 */
@Service
@RequiredArgsConstructor
public class PoiServiceImpl implements PoiService {

    private final PoiMapper poiMapper;


    //根据id获取
    @Override
    public Poi getById(Integer senderId) {
        return poiMapper.selectById(senderId);
    }


    //计算质心坐标,返回坐标字符串
    @Override
    public String getBarycenter(List<GoodsDemand> goodsDemandList) {
        List<Double> latList = new ArrayList<>();
        List<Double> lngList = new ArrayList<>();
        List<Double> qualityList = new ArrayList<>();

        for (GoodsDemand goodsDemand : goodsDemandList) {
            Double lat = getById(goodsDemand.getSenderId()).getLat();
            Double lng = getById(goodsDemand.getOwnerId()).getLng();
            Double weight = goodsDemand.getWeight();
            latList.add(lat);
            lngList.add(lng);
            qualityList.add(weight);
        }

        return CalculateUtil.getBarycenter(latList, lngList, qualityList);
    }
}
